﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsumeSys.Orm;

namespace ConsumeSys.BLL
{
    public class UserBLL
    {
        /// <summary>
        /// 实例化用户数据操作层
        /// </summary>
        private DAL.UserDAL dal_UserDAL = new DAL.UserDAL();

        #region 用户操作

        /// <summary>
        /// 返回登录用户
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>User</returns>
        public Model.User GetLoginUser(string username, string password)
        {
            return dal_UserDAL.GetLoginUser(username, password);
        }

        /// <summary>
        /// 返回登录用户
        /// </summary>
        /// <returns>User</returns>
        public Model.User GetLoginUser()
        {
            return dal_UserDAL.GetUser(Common.Globals.GetLoginUserCookie());
        }

        /// <summary>
        /// 返回User
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>User</returns>
        public Model.User GetUser(int id)
        {
            return dal_UserDAL.GetUser(id);
        }

        /// <summary>
        /// 返回User
        /// </summary>
        /// <param name="username">用户名</param>
        /// <returns>User</returns>
        public Model.User GetUser(string username)
        {
            return dal_UserDAL.GetUser(username);
        }

         /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user">需要添加的用户Model</param>
        /// <returns>受影响的行数</returns>
        public int AddUser(Model.User user) 
        {
            return dal_UserDAL.AddUser(user);
        }

        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="realName">真实姓名</param>
        /// <returns>Paging</returns>
        public Paging<Model.User> GetPagingUser(int pageIndex, int pageSize, string realName)
        {
            Paging<Model.User> _paging = dal_UserDAL.GetPagingUser(pageIndex, pageSize, realName);
            return _paging;
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="ids">主键集合</param>
        /// <returns>受影响的行数</returns>
        public int DeleteUser(string ids)
        {
            return dal_UserDAL.DeleteUser(ids);
        }

        /// <summary>
        /// 返回用户list
        /// </summary>
        /// <returns>List</returns>
        public List<Model.User> GetUserList()
        {
            return dal_UserDAL.GetUserList();
        }

        #endregion
    }
}
